package entityclasses;

import socialappexception.AlreadyExistException;
import entityclasses.Share;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.swing.JOptionPane;
import entityclasses.Group;
import entityclasses.Person;
import entityclasses.Related;
import entityclasses.RelationshipStatus;
import visitors.ShowPersonsWithGroupsVisitor;

public class Profile {

	private String profileName;
	private String createDate;
	private Vector<Person> friends;
	private Vector<Person> friendRequests;
	private Vector<Group> groups;
	private RelationshipStatus relationship;
	private Vector<Related> relateds;
	private Vector<Share> shares;

        public Profile()
        {
        }
        
        /**
     * @return the profileName
     */
    public String getProfileName() {
        return profileName;
    }

    /**
     * @param profileName the profileName to set
     */
    public void setProfileName(String profileName) {
        this.profileName = profileName;
    }

    /**
     * @return the createDate
     */
    public String getCreateDate() {
        return createDate;
    }

    /**
     * @param createDate the createDate to set
     */
    public void setCreateDate(String dateNow) {
       this.createDate = dateNow;
    }

    /**
     * @return the friends
     */
    public Vector<Person> getFriends() {
        return friends;
    }

    /**
     * @param friends the friends to set
     */
    public void setFriends(Vector<Person> friends) {
        this.friends = friends;
    }

    /**
     * @return the friendRequests
     */
    public Vector<Person> getFriendRequests() {
        return friendRequests;
    }

    /**
     * @param friendRequests the friendRequests to set
     */
    public void setFriendRequests(Vector<Person> friendRequests) {
        this.friendRequests = friendRequests;
    }

    /**
     * @return the groups
     */
    public Vector<Group> getGroups() {
        return groups;
    }

    /**
     * @param groups the groups to set
     */
    public void setGroups(Vector<Group> groups) {
        this.groups = groups;
    }

    /**
     * @return the relationship
     */
    public RelationshipStatus getRelationship() {
        return relationship;
    }

    /**
     * @param relationship the relationship to set
     */
    public final void setRelationship(RelationshipStatus relationship) {
        this.relationship = relationship;
    }

    /**
     * @return the relateds
     */
    public Vector<Related> getRelateds() {
        return relateds;
    }

    /**
     * @param relateds the relateds to set
     */
    public void setRelateds(Vector<Related> relateds) {
        this.relateds = relateds;
    }

    /**
     * @return the shares
     */
    public Vector<Share> getShares() {
        return shares;
    }

    /**
     * @param shares the shares to set
     */
    public void setShares(Vector<Share> shares) {
        this.shares = shares;
    }
    @Override
    public String toString()
    {
        return ""+getProfileName()+
                getFriendRequests().size()+
                getCreateDate()+
                getFriends().size()+
                getGroups().size()+
                getRelateds().size()+
                getRelationship()+
                getShares().size();
    }
    
    public String showAllPersonsWithGroups()
    {
        String allPersonsWithGroups = "";
        for(int i=0;i<groups.size();i++)
        {
            ShowPersonsWithGroupsVisitor v = new ShowPersonsWithGroupsVisitor();
            allPersonsWithGroups +="Ana Grup: "+groups.elementAt(i).getName() + "\n";
            allPersonsWithGroups += groups.elementAt(i).accept(v);
        }
        return allPersonsWithGroups;
    }
    
    public void addGroup(Group g)
    {
        try {
            if(!groups.contains(g))
            groups.add(g);
            else 
            throw new AlreadyExistException(g.getName() + " grubu zaten var.");
        } catch (AlreadyExistException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage(), "Hata", JOptionPane.ERROR_MESSAGE);
        }
    }

    public void removeGroup(Group g) {
               try {
            if(groups.contains(g))
            groups.remove(g);
            else 
            throw new AlreadyExistException(g.getName() + " grubu zaten silinmiş");
        } catch (AlreadyExistException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage(), "Hata", JOptionPane.ERROR_MESSAGE);
        }
    }

}
